layui.use(['layer', 'form', 'table', 'admin', 'ax', 'func','laydate'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;
    var laydate = layui.laydate;
    //渲染时间选择框
    laydate.render({
        elem: '#loanDate',
        range: true,
        tiger: 'click'
    });
    /**
     * 系统管理--消息管理
     */
    var Notice = {
        tableId: "noticeTable"    //表格id
    };
    $("#condition").on("input",function(e){
        //获取input输入的值
        Notice.search();
    });
    form.on('select(borrowerId)', function(data){
        Notice.search();
    });
    /**
     * 选中行效果
     */
    table.on('row(noticeTable)',function(obj){
        $(obj.tr).siblings().css("background-color","");
        obj.tr.css({"background-color":"#dadad9"});
    });
    /**
     * 检索借款人
     */
    var languageAjax = new $ax(Feng.ctxPath + "/flowInfo/borrowerInfo");
    var languageResult = languageAjax.start();

    $.each(languageResult, function( index, val ) {
        $("#borrowerId").append("<option value='"+val.id+"'>"+val.name+"</option>");
    } );
    form.render('select');

    /**
     * 获取已借贷款人
     */
    var borrowedAjax = new $ax(Feng.ctxPath + "/flowInfo/borrowed");
    var borrowedResult = borrowedAjax.start();
    $("#borrowed").append("<option value=''>"+borrowedResult.length+"</option>");
    $.each(borrowedResult, function( index, val ) {
        $("#borrowed").append("<option value='"+val.id+"'>"+val.name+"</option>");
    } );
    form.render('select');

    /**
     * 获取未借贷款人
     */
    var notBorrowedAjax = new $ax(Feng.ctxPath + "/flowInfo/notBorrowed");
    var notBorrowedResult = notBorrowedAjax.start();
    $("#notBorrowed").append("<option value=''>"+notBorrowedResult.length+"</option>");
    $.each(notBorrowedResult, function( index, val ) {
        $("#notBorrowed").append("<option value='"+val.id+"'>"+val.name+"</option>");
    } );
    form.render('select');
    /**
     * 初始化表格的列
     */
    Notice.initColumn = function () {
        return [[
            {type: 'checkbox',hide:true},
            {field: 'id', align: "center", hide: true, sort: true, title: 'id'},
            //{field: 'borrower_id', align: "center",sort: true, title: 'borrower_id'},
            {align: 'center', type: "numbers", title: '序号'},
            {field: 'loan_date', align: "center", sort: true, title: '日期',event:'date',width:130},
            {field: 'name', align: "center", sort: true, title: '姓名',width:80},
            {field: 'summary', align: "center", sort: true, title: '摘要'},
            {field: 'debit', align: "center", sort: true, title: '借方',totalRow:true},
            {field: 'credit', align: "center", sort: true, title: '贷方',totalRow:true},
            {field: 'balance', align: "center", sort: true, title: '余额'},
            {field: 'bj', align: "center", sort: true, title: '借款本金'},
            {field: 'yll', align: "center", sort: true, title: '月利率'},
            {field: 'month', align: "center", sort: true, title: '还款月份'},
            {field: 'hkje', align: "center", sort: true, title: '还款本金'},
            {field: 'lx', align: "center", sort: true, title: '应还款利息'},
            {field: 'remark', align: "center", sort: true, title: '备注',width: 80},
            //{align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 200}
        ]];
    };

    /**
     * 点击查询按钮
     */
    Notice.search = function () {
        var queryData = {};
        queryData['borrowerId'] = $("#borrowerId").val();
        queryData['loanDate'] = $("#loanDate").val();
        table.reload(Notice.tableId, {
            where: queryData, page: {curr: 1}
        });
    };


    // 渲染表格
    var tableResult = table.render({
        elem: '#' + Notice.tableId,
        url: Feng.ctxPath + '/flowInfo/listSearch',
        page: true,
        height: "full-118",
        cellMinWidth: 100,
        totalRow:true,
        cols: Notice.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        Notice.search();
    });
});
